<?php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\View;

class Base extends BaseController
{
    

    public function initialize() {
       
    //  // 判定用户是否登录
    $login =session('userAccount');     
    if(!$login) {
          View::assign('loginsf','');
    //   return $this->redirect('/index/login');
    }else {
         View::assign('loginsf',$login['username']);
    }
    
 
        //系统参数
        $configData=Db::name('config')->field('value')->select();
        foreach($configData as $k=>$v){
          if($k==0){
            View::assign('web_title', $v['value']);//首页title
          }
          if($k==2){
            View::assign('web_keywords', $v['value']);//首页关键字
          }
          if($k==12){
            View::assign('web_description', $v['value']);//首页描述
          }
          if($k==3){
            View::assign('copyright', $v['value']);//版权信息
          }
          if($k==4){
            View::assign('beian', $v['value']);//备案号
          }
          if($k==6){
            View::assign('address', $v['value']);//地址
          }
          if($k==10){
            View::assign('email', $v['value']);//邮箱
          }
          if($k==7){
            View::assign('tel1', $v['value']);//电话
          }
           if($k==13){
            View::assign('web_tongzhi', $v['value']);//电话
          }
          
        }

    }
   public function password_salt($str){
      $salt='ddsEf6KJ';
      return md5($str.$salt);
    }
     public function tongzhi($post_data){
     $configData=Db::name('tongzhi')->where('id',1)->find();   
   $webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=".$configData['wxkey'];   
# curl初始化
   $curl = curl_init();
#需要推送的url
curl_setopt($curl, CURLOPT_URL, $webhook);
curl_setopt($curl, CURLOPT_POST, 1);
#content必须是utf8编码
curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: application/json;charset=utf-8'));
#content 为需要推送的内容

curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$data = curl_exec($curl);
curl_close($curl);
    }
 public function qingqiu($url,$data){
      $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $shouquan = curl_exec($ch);
        curl_close($ch);
          return $shouquan;
    }
 public function apiurl($url,$method,$token,$bodys){
     

    // 配置headers 
    $headers[] = "Accept:*/*";
    $headers[] = "Accept-Encoding:gzip,deflate,sdch";
    $headers[] = "Accept-Language:zh-CN,zh;q=0.8";
    $headers[] = "Connection:close";
    $headers[] = "Authorization: Token 6zFyCruNDuX2YdEXJNFY" ;
    // 创建连接
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($bodys));
    curl_setopt($curl, CURLOPT_ENCODING, "");
    // 发送请求
    $response = curl_exec($curl);
    curl_close($curl);
    
    // 读取响应
    $data=urldecode (json_encode($response)); 
    return($data);
  
    }



}
